<%@page import="org.proddevplm.constants.UserConstants"%>
<%@page import="org.proddevplm.dao.data.User"%>
<%@page import="org.proddevplm.dao.data.Roles"%>
<%@page import="org.proddevplm.dao.data.Project"%>
<%@page import="org.proddevplm.dao.data.RelationMatrix"%>
<%@page import="java.util.List"%>
<script>
    function loadTab(request, page) {

   	    if (isDefined("pollChatData"))
   	  	{
   	  		window.clearInterval(pollChatData);
   	  	}
    	   
    	$.post(request, function(data) {
            $("#tabcontent").load(page);
        });
    }
    
    function loadTabWOReq(page) {
    	$("#tabcontent").load(page);
    }

    $(document).ready(function() {
        $("#preloader").hide();

        $("#tab1").click(function() {
            loadTab("/proddev/controller?manager=flowManager&method=2", "content/project/home/homePage.jsp");
        });
		
        $("#tab2").click(function() {
        	loadTab("/proddev/controller?manager=productManager&method=1", "content/project/product/allProducts.jsp");
        });

        $("#tab3").click(function() {
        	loadTab("/proddev/controller?manager=dataAccessManager&method=16", "content/project/roadmap/roadMap.jsp");
        });
        
        $("#tab4").click(function(){
        	loadTab("/proddev/controller?manager=dataAccessManager&method=21", "content/project/activities/activitiesPage.jsp");
        });
        
        $("#tab5").click(function(){
        	loadTabWOReq("content/project/workspace/workingArea.jsp");
        })
        
        $("#tab6").click(function(){
        	loadTab("/proddev/controller?manager=dataAccessManager&method=14", "content/project/resources/resourcesPage.jsp");
        });
        
                
        $("#tab7").click(function(){
        	loadTabWOReq("content/project/team/projectTeam.jsp");
        });
        
        $("#tab8").click(function(){
        	loadTabWOReq("content/project/openRoom/chat.jsp");
        });
        
        $("#tab11").click(function(){
        	loadTab("/proddev/controller?manager=adminManager&method=5","content/project/administration/administration.jsp");
        });
        
        $("#tab12").click(function(){
        	loadTabWOReq("content/project/devTools/devToolsPage.jsp");
        });
        
        $("#tab13").click(function(){
        	loadTab("/proddev/controller?manager=dataAccessManager&method=30","content/project/productFollowUp/productFollowUp.jsp")
        });
        

        $(function() {
            $("#tabs").tabs();
            $("#tab12").hide();
        });

        <%
            String currentTab = (String) session.getAttribute("currentTab");
            if (currentTab==null) { %>
                 $("#tab1").click();
            <%} else { %>
                 $("#<%=currentTab%>").click();
            <%}
        %>


    });


</script>

<%
	Integer productId = (Integer) session.getAttribute("productId");
	User loggedUser = (User) session.getAttribute(UserConstants.USER);
	String currentRole = "";
	
	List relMatrix = (List)session.getAttribute("relationMatrix");
	int projectId = (Integer)session.getAttribute("projectId");
	for (int index=0; index<relMatrix.size(); index++){
		RelationMatrix rm = (RelationMatrix)relMatrix.get(index);
		User user = rm.getUser();
		if(user.getId()==loggedUser.getId()){
			Roles userRole = rm.getRole();
			currentRole = userRole.getRole();
		}
	}
%>

<div id="tabs" style="width:auto; font-size:small; ">

    <ul>
        <li><a id="tab1" href="dummy">Home</a></li>
        <li><a id="tab2" href="dummy">Products</a></li>
        <%if(productId!=null){%>
	        <li><a id="tab3" href="dummy">Project Roadmap</a></li>
	        <li><a id="tab4" href="dummy">Activities</a></li>
	        <li><a id="tab5" href="dummy">Workspace</a></li>
	        <li><a id="tab6" href="dummy">Resources</a></li>
	        <li><a id="tab7" href="dummy">Team</a></li>
	        <li><a id="tab8" href="dummy">Open Room</a></li>
	        <li><a id="tab9" href="dummy">View</a></li>
	        <li><a id="tab10" href="dummy">Help</a></li>
	        <%if("Project Manager".equals(currentRole)){ %>
		        <li><a id="tab11" href="dummy">Administration</a></li>
		        <li><a id="tab12" href="dummy">Development tools</a></li>
		    <%} %>
	        <li><a id="tab13" href="dummy">Product follow-up</a></li>
        <%} %>
    </ul>
    <div id="tabcontent" style="margin-top:-10px;"></div>
    <div style="clear:both"></div>

</div>